<template>
	<view class="login">
		<uv-navbar leftIcon="arrow-leftward" leftIconColor="#FFF" placeholder autoBack bgColor="#161714" />
		<view class="content">
			<view class="title">{{$t('login.欢迎登入')}}</view>
			<view class="item">
				<input type="text" :placeholder="$t('login.请输入邮箱')" v-model="form.phone">
			</view>
			<view class="item" v-if="password">
				<!-- <input type="text" password placeholder="请输入密码" v-model="form.password"> -->
				<input type="text" password :placeholder="$t('login.请输入密码')" v-model="form.password">
				<view class="icon" @click="password=!password">
					<image src="@/static/images/12.png"></image>
				</view>
			</view>
			<view class="item" v-else>
				<input type="text" :placeholder="$t('login.请输入密码')" v-model="form.password">
				<view class="icon" @click="password=!password">
					<image src="@/static/images/13.png"></image>
				</view>
			</view>
			<view class="cell">
				<view @click="router('/pages/login/register')">{{$t('login.注册')}}</view>
				<view @click="router('/pages/login/forgot')">{{$t('login.忘记密码')}}</view>
			</view>
			<view class="submit" @click="submit">{{$t('login.登入')}}</view>
			<view class="desc" @click="checkbox=!checkbox">
				<image src="@/static/images/checked.png" v-if="checkbox"></image>
				<image src="@/static/images/checkbox.png" v-else></image>
				<view>{{$t('login.协议')}}<text
						@click.stop="router('/pages/login/article?key=use_provision')">{{$t('login.使用条款')}}</text>{{$t('login.和')}}<text
						@click.stop="router('/pages/login/article?key=privacy')">{{$t('login.隐私条款')}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		login
	} from "@/request/api";
	import {
		ref,
		reactive
	} from "vue";
	import useStore from "@/stores/index.js";
	const {
		useLoginStore
	} = useStore();
	import useBase from "@/hooks/useBase.js";
	const {
		router
	} = useBase();
	const password = ref(true);
	const checkbox = ref(false);
	const form = reactive({
		phone: "",
		password: ""
	});
	const submit = async () => {
		if (!checkbox.value) {
			uni.$uv.toast("请先阅读协议");
			return
		}
		let {
			token
		} = await login(form);
		uni.$uv.toast("操作成功");
		useLoginStore.changeToken(token);
		setTimeout(() => {
			uni.switchTab({
				url: '/pages/tabbar/my'
			})
		}, 1500);
	};
</script>

<style scoped lang="scss">
	.login {
		.content {
			padding: 0 60rpx;
			box-sizing: border-box;

			.title {
				color: #FFFFFF;
				font-size: 62rpx;
				font-weight: bold;
				padding: 60rpx 0 110rpx;
				box-sizing: border-box;
			}

			.item {
				height: 110rpx;
				border-radius: 20rpx;
				margin-bottom: 30rpx;
				padding: 0 40rpx;
				box-sizing: border-box;
				background: #2F2F2F;
				display: flex;
				align-items: center;

				input {
					flex: 1;
					color: #999999;
					font-size: 36rpx;

				}

				.icon {
					padding-left: 40rpx;
					box-sizing: border-box;

					image {
						width: 40rpx;
						height: 40rpx;
					}
				}
			}

			.cell {
				padding: 10rpx 0 110rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: space-between;

				view {
					color: #999999;
					font-size: 28rpx;
				}
			}

			.submit {
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #111111;
				font-size: 28rpx;
				font-weight: bold;
				border-radius: 20rpx;
				background: #DDF247;
			}

			.desc {
				margin-top: 300rpx;
				box-sizing: border-box;
				display: flex;
				align-items: center;

				image {
					width: 40rpx;
					height: 40rpx;
				}

				view {
					flex: 1;
					color: #999999;
					font-size: 26rpx;
					padding-left: 12rpx;
					box-sizing: border-box;
				}
			}
		}
	}
</style>